﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;

namespace AcmeSportsStore
{
    public partial class TestForm : Form
    {
        SportsStore mStore = new SportsStore();
        Customers mCustomers = new Customers();

        LayoutController mFormLayoutCtrl = null;
        
        public TestForm()
        {
            InitializeComponent();
        }

        void GenerateSportsStoreData()
        {
            mStore.Clear();
            FileReader fr = new FileReader(
                new StreamReader("E:\\sportsItemsInfo.txt"),
                null,
                null);
            mStore = fr.ReadSportsItems();
        }

        void GenerateCustomerStoreData()
        {
            mCustomers.Clear();
            FileReader fr = new FileReader(null, 
                new StreamReader("E:\\customersInfo.txt"),
                null);
            mCustomers = fr.ReadCustomers();
        }

        private void btnOrderById_Click(object sender, EventArgs e)
        {
            int count = mCustomers.Count;

            lstMain.Items.Clear();
            for (int i = 0; i < count; i++)
            {
                CustomersItem item = mCustomers.GetItemByIndexerForId(i);
                lstMain.Items.Add(item.ToString());
            }
        }

        private void TestForm_Load(object sender, EventArgs e)
        {
          //  GenerateSportsStoreData();
            GenerateCustomerStoreData();
            mFormLayoutCtrl = new LayoutController(this);
        }

        private void btnOrderByName_Click(object sender, EventArgs e)
        {
            int count = mCustomers.Count;
            lstMain.Items.Clear();
            
            for (int i = 0; i < count; i++)
            {
                CustomersItem item = mCustomers.GetItemByIndexerForName(i);
                lstMain.Items.Add(item.ToString());
            }
        }

        private void btnOrderByPrice_Click(object sender, EventArgs e)
        {
            int count = mStore.Count;

            lstMain.Items.Clear();
            for (int i = 0; i < count; i++)
            {
                SportsItem item = mStore.GetItemByIndexForPrice(i);
                lstMain.Items.Add(item.ToString());
            }
        }

        private void btnOrderByDesc_Click(object sender, EventArgs e)
        {
            int count = mCustomers.Count;

            lstMain.Items.Clear();
            for (int i = 0; i < count; i++)
            {
                CustomersItem item = mCustomers.GetItemByIndexerForAddress(i);
                lstMain.Items.Add(item.ToString());
            }
        }

        private void TestForm_Resize(object sender, EventArgs e)
        {
            if (mFormLayoutCtrl != null)
            {
                mFormLayoutCtrl.UpdateAfterResizing();
            }
        }

        private void TestForm_Layout(object sender, LayoutEventArgs e)
        {
        }
    }
}
